#!/bin/bash
# - memcached_memsize
# - use_hugetlbfs

. "$LKP_SRC/lib/unit.sh"
. "$LKP_SRC/lib/common.sh"
. "$LKP_SRC/lib/reproduce-log.sh"

: "${memcached_memsize:=$(to_mb 64m)}"

config_hugepage()
{
	if parse_bool -q "$use_hugetlbfs"; then
		log_eval hugeadm --pool-pages-min DEFAULT:$(to_mb "$memcached_memsize")M
	fi
}

run_memcached()
{
	preload=
	parse_bool -q "$use_hugetlbfs" && preload="LD_PRELOAD=libhugetlbfs.so HUGETLB_MORECORE=yes"
	log_eval "$preload" memcached -d -P /tmp/memcached.pid -m "$(to_mb "$memcached_memsize")" -u root
}

config_hugepage
run_memcached
